home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Reference Guide / C-C++ Interactive Reference Guide.iso / c_ref / csource5 / 343_01 / cutp.c < prev    next >
C/C++ Source or Header  |  1992-04-21  |  4KB  |  130 lines

  1.  
  2.  
  3.  
  4.        /***********************************************
  5.        *
  6.        *       file d:\cips\cutp.c
  7.        *
  8.        *       Functions: This file contains
  9.        *          cut_image_piece
  10.        *          paste_image_piece
  11.        *          check_cut_and_paste_limits
  12.        *
  13.        *       Purpose:
  14.        *          These functions cut pieces out
  15.        *          of images and paste them back into
  16.        *          images.
  17.        *
  18.        *       External Calls:
  19.        *          wtiff.c - does_not_exist
  20.        *                    round_off_image_size
  21.        *                    create_allocate_tiff_file
  22.        *                    write_array_into_tiff_image
  23.        *          tiff.c - read_tiff_header
  24.        *          rtiff.c - read_tiff_image
  25.        *
  26.        *
  27.        *       Modifications:
  28.        *          3 April 1992 - created
  29.        *
  30.        *************************************************/
  31.  
  32. #include "d:\cips\cips.h"
  33.  
  34.      /*******************************************
  35.      *
  36.      *   cut_image_piece(...
  37.      *
  38.      *   This function cuts out a rectangular
  39.      *   piece of an image.  This rectangle can
  40.      *   be any shape so long as no dimension
  41.      *   is greater than ROWS or COLS.
  42.      *
  43.      *******************************************/
  44.  
  45.  
  46. cut_image_piece(name, the_image, il, ie, ll, le)
  47.    char   name[];
  48.    int    il, ie, ll, le;
  49.    short  the_image[ROWS][COLS];
  50.  
  51. {
  52.    if(does_not_exist(name)){
  53.       printf("\n\ncut_image_piece>> ERROR "
  54.              "image file does not exist %s", name);
  55.       return(-1);
  56.    }  /* ends if does_not_exist */
  57.  
  58.    read_tiff_image(name, the_image, il, ie, ll, le);
  59.  
  60. }  /* ends cut_image_piece */
  61.  
  62.  
  63.  
  64.  
  65.      /*******************************************
  66.      *
  67.      *   paste_image_piece(...
  68.      *
  69.      *   This function pastes a rectangular
  70.      *   piece of an image into another image.
  71.      *   This rectangle can be any shape so long
  72.      *   as no dimension is greater than ROWS or COLS.
  73.      *   The rectangle to be pasted into the image
  74.      *   is described by the il, ie, ll, le
  75.      *   parameters.
  76.      *
  77.      *   You pass is the out_image array just in
  78.      *   case you need to allocate the destination
  79.      *   image.
  80.      *
  81.      *******************************************/
  82.  
  83.  
  84. paste_image_piece(dest_name, source_name, the_image,
  85.                   out_image, il, ie, ll, le)
  86.    char   dest_name[], source_name[];
  87.    int    il, ie, ll, le;
  88.    short  the_image[ROWS][COLS],
  89.           out_image[ROWS][COLS];
  90.  
  91. {
  92.    struct tiff_header_struct image_header;
  93.  
  94.    if(does_not_exist(dest_name)){
  95.       printf("\n\ncut_image_piece>> "
  96.              "image file does not exist %s", dest_name);
  97.       read_tiff_header(source_name, &image_header);
  98.       create_allocate_tiff_file(dest_name, &image_header,
  99.                                 out_image);
  100.    }  /* ends if does_not_exist */
  101.  
  102.    write_array_into_tiff_image(dest_name, the_image,
  103.                                il, ie, ll, le);
  104.  
  105. }  /* ends paste_image_piece */
  106.  
  107.  
  108.  
  109.      /*******************************************
  110.      *
  111.      *   check_cut_and_paste_limits(...
  112.      *
  113.      *   This function looks at the line and
  114.      *   element parameters and ensures that they
  115.      *   are not bigger than ROWS and COLS.  If
  116.      *   they are bigger, the last element or
  117.      *   last line parameters are reduced.
  118.      *
  119.      *******************************************/
  120.  
  121. check_cut_and_paste_limits(il, ie, ll, le)
  122.    int *il, *ie, *ll, *le;
  123. {
  124.    if((*ll - *il) > ROWS)
  125.       *ll = *il + ROWS;
  126.    if((*le - *ie) > COLS)
  127.       *le = *ie + COLS;
  128. }  /* ends check_cut_and_paste_limits */
  129.  
  130.